# Maintainer: Alex Xu (Hello71) <alex_y_xu@yahoo.ca>
pkgname=7zip
pkgver=23.01
_pkgver=${pkgver//./}
pkgrel=0
pkgdesc="File archiver with a high compression ratio"
url="https://7-zip.org/"
arch="all"
license="LGPL-2.0-only"
subpackages="$pkgname-doc"
source="https://7-zip.org/a/7z$_pkgver-src.tar.xz
	armv7.patch
	7-zip-flags.patch
	7-zip-musl.patch
	"
builddir="$srcdir"

provides="7zip-virtual p7zip=$pkgver-r$pkgrel"
replaces="p7zip"
provider_priority=100

build() {
	cd CPP/7zip/Bundles/Alone2
	mkdir -p b/g
	# TODO: enable asm (requires jwasm or uasm)
	# DISABLE_RAR: RAR codec is non-free
	# -D_GNU_SOURCE: broken sched.h defines
	make -f ../../cmpl_gcc.mak \
		CC="${CC:-cc} $CFLAGS $LDFLAGS -D_GNU_SOURCE" \
		CXX="${CXX:-c++} $CXXFLAGS $LDFLAGS -D_GNU_SOURCE" \
		DISABLE_RAR=1
}

check() {
	# no proper test suite so just try to compress and decompress some files
	mkdir tmp
	CPP/7zip/Bundles/Alone2/b/g/7zz a tmp/7z$_pkgver-src.7z Asm C CPP DOC
	cd tmp
	../CPP/7zip/Bundles/Alone2/b/g/7zz x 7z$_pkgver-src.7z
	# TODO: check if extracted result is identical
}

package() {
	install -Dm755 CPP/7zip/Bundles/Alone2/b/g/7zz "$pkgdir"/usr/bin/7zz
	ln -s 7zz "$pkgdir"/usr/bin/7z

	install -Dm644 "$builddir"/DOC/* -t "$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
e39f660c023aa65e55388be225b5591fe2a5c9138693f3c9107e2eb4ce97fafde118d3375e01ada99d29de9633f56221b5b3d640c982178884670cd84c8aa986  7z2301-src.tar.xz
e52e542709a23ced76b651adf54609efae705801e940e74310ae4e67070bdb3841da5b801362aa0329b77993cdc3f6cd63ac2802240b16cde865f9d01bb1936d  armv7.patch
dfecb69861d00ee47311d83930adf80321b3c95ae01ce325677bde7aee6aa880a1979b0aa2909d9acb7a88ff31f910ac545ac218a0b5fd9e1270df2276b46d44  7-zip-flags.patch
c652a87ad95f61901820adb61f3d1ceacedcb8aeaf9e89b2b728b7372eff67d9669eb363d5b2d2fb848ff2d8c5a727134fe13cc77d1215df7b2d32fe87711ebf  7-zip-musl.patch
"
